#e
#Title[puqƂv]
#Text[]
#Player[FREE]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {

let Norma=5;//Be̐ݒ
let SpellTimer=9000;//Ԃ̐ݒit[Pʁj
let StepUp=[1,2,3,4];//iKڍs閇ݒi܂܂Őݒ\jBStepUp1`5ibooleanj܂łA͖BtrueɂȂ

#include_function ".\..\txt/data.txt"

    let imgBoss =GetCurrentScriptDirectory ~ "..\lib/dot_sanae.png"; 

    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetCenterY-50;


    @Initialize {
       LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	InitializeDoubleSpoiler;
	DrawSpellName(imgSpellName,5,236,233,262);
	DoubleSpoilerSetShotAutoDeleteClip(0,0,0,0);
        LoadGraphic(imgBoss);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	FinalizeDoubleSpoiler;
    }
	@BackGround
	{


	}

    // C^XN
task TMain 
{
	yield;
	standBy;
	Shot;
	Shot2;
	step;
}


sub standBy//ʒu
{
	SetAction(ACT_MOVE, 30);
	let wIni = 30;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

let ShotLoop=5;
let ShotWay=8;
let StarWaitTime=210;

task step
{
	while(!StepUp1){yield;}
	ShotLoop=6;
	ShotWay=10;
	StarWaitTime=180;
	while(!StepUp2){yield;}
	ShotLoop=7;
	ShotWay=12;
	StarWaitTime=150;
	while(!StepUp3){yield;}
	ShotWay=14;
	while(!StepUp4){yield;}
	ShotWay=18;
	StarWaitTime=120;
}

task Shot2
{
loop
{
let angle=rand(0,360);
SetAction(ACT_SHOT_A,165);
	RedShot2(angle);
	wait(45);
	BlueShot2(angle);
	wait(120);
	moveToPlayer(rand(40, 60), rand(-10, 10), 30,
                     GetClipMinX + 48, GetClipMinY +  64,
                     GetClipMaxX - 48, GetClipMinY + 144);
	wait(30);
	
}
}

task RedShot2(angle)
{
	loop(ShotLoop)
	{
	ascent(let j in 0..3)
	{
	ascent(let i in 0..ShotWay)
	{	
	//CreateShot01(GetX,GetY,2.5,angle+i*360/ShotWay,RED11,5);
	DoubleSpoilerCreateShot01(GetX,GetY,2.5,angle+i*360/ShotWay,65,5,"RED",160,50,160);
	}
	angle+=2.5;
	wait(4);
	}
	angle+=6-2.25;
	wait(8);
	}
}

task BlueShot2(angle)
{
	loop(ShotLoop)
	{
	ascent(let j in 0..3)
	{
	ascent(let i in 0..ShotWay)
	{	
//	CreateShot01(GetX,GetY,3.5,angle+i*360/ShotWay,BLUE11,5);
	DoubleSpoilerCreateShot01(GetX,GetY,3.5,angle+i*360/ShotWay,70,5,"BLUE",160,50,160);
	}
	angle-=2.5;
	wait(4);
	}
	angle-=6-2.25;
	wait(8);
	}
}

task Shot
{
wait(120);
	loop
	{
		StarCentralShot(GetPlayerX,GetClipMinY,125,2.5,90,129,10);
		DummyStarCentralShot(GetPlayerX,GetClipMinY,125,2.5,90,129,10);
		wait(StarWaitTime);
	}
}

task LayShot(Sobj,r)
{
	let obj = Obj_Create(OBJ_SHOT);
	ObjShot_SetGraphic(obj, 241);
	//ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	let dis=r*2*sin(72);
	let speed=5;
	let r=0;
	let pangle=90+GetAngleToPlayer-90;
	let GPAngle=GetAngleToPlayer;
	let t=0;
	Obj_SetPosition(obj,Obj_GetX(Sobj)+r*cos(Obj_GetAngle(Sobj)+162),Obj_GetY(Sobj)+r*sin(Obj_GetAngle(Sobj)+162));
	loop(floor(dis/speed))
	{
		Obj_SetPosition(obj,Obj_GetX(Sobj)+r*cos(Obj_GetAngle(Sobj)+162),Obj_GetY(Sobj)+r*sin(Obj_GetAngle(Sobj)+162));
		r+=speed;
		wait(1);
	}
	Obj_Delete(obj);
}

task StarShot(Cobj,angle,r)
{//̊e_̈ʒuɂe
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj, Obj_GetX(Cobj), Obj_GetY(Cobj));
	ObjShot_SetGraphic(obj, 158);
	//Obj_SetAngle(obj,angle);
	Obj_SetAngle(obj,angle+162);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
//	Obj_SetAlpha(obj,0);
//	Obj_SetCollisionToPlayer(obj,false);
	ObjLaser_SetLength(obj,r*2*sin(72));
	ObjLaser_SetWidth(obj,15);
ObjLaser_SetSource(obj,false);
	let X;
	let Y;
	let VanishJudg=false;
	let count=0;
	//let r=150;//̒_܂ł̋
	while(!Obj_BeDeleted(Cobj))
	{
		Obj_SetAngle(obj,angle+162);
		//Obj_SetAngle(obj,angle);
		Obj_SetPosition(obj,Obj_GetX(Cobj)+r*cos(angle),Obj_GetY(Cobj)+r*sin(angle));
		if(count>=4)
		{
		//	LayShot(obj,r);
			count=0;
		}
		angle+=1.1;
		count+=1;
		wait(1);
	}
	Obj_Delete(obj);
}

task StarCentralShot(let x,let y,let r,let speed,let angle,let graphic,let delay)
{//̒Sɂe̍쐬
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj,angle);
	Obj_SetSpeed(obj,speed);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	ascent(let i in 0..5)
	{
	StarShot(obj,i*72,r);
	}
	while(!Obj_BeDeleted(obj))
	{
		wait(1);
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_GetX(obj)<GetClipMinX-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//E[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
	}
}

task DummyStarCentralShot(let x,let y,let r,let speed,let angle,let graphic,let delay)
{//̒Sɂe̍쐬
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y);
	Obj_SetAngle(obj,angle);
	Obj_SetSpeed(obj,speed);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	//ObjShot_SetBombResist(obj,true);
	Obj_SetAlpha(obj,0);
	Obj_SetAutoDelete(obj,false);

	let X;
	let Y;
	let VanishJudg=false;

	while(!Obj_BeDeleted(obj))
	{
		wait(1);
		X=Obj_GetX(obj);
		Y=Obj_GetY(obj);
		if(Obj_GetX(obj)<GetClipMinX-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetX(obj)>GetClipMaxX+64)//E[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)<GetClipMinY-64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
		if(Obj_GetY(obj)>GetClipMaxY+64)//[ł̋
		{
			Obj_Delete(obj);
			VanishJudg=true;
        	}
	}
	if(VanishJudg==false)
	{
		if(DistanceToPlayer(X,Y)<=125)
		{
			RiskShot(600);
		}
		if(DistanceToBoss(X,Y)<=125)
		{
			ClearShot;
		}
		BasePoint(1000);
	}
}

#include_function ".\..\lib/lib_anime_Sanae.txt"
}
